package com.zjw.zy.base;

import android.content.Context;
import android.util.AttributeSet;

import androidx.annotation.Nullable;

/**
 * @author ：zhong.jw
 * @date ：Created in 2023/1/17 13:24
 */
public abstract class EventViewGroup extends BaseViewGroup {

    @Nullable
    protected EventListener listener;

    public EventViewGroup(Context context) {
        super(context);
    }

    public EventViewGroup(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public EventViewGroup(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    public void bindEventListener(EventListener listener) {
        this.listener = listener;
    }

    /**
     * 发送此ViewGroup产生的事件
     *
     * @param event:事件 int
     * @param args:参数
     */
    protected final void sendEvent(int event, Object... args) {
        if (listener != null) {
            listener.onEvent(event, args);
        }
    }


    public interface EventListener {
        void onEvent(int event, Object... args);
    }
}
